<?php

class Service_hot extends MY_Service
{
    public function __construct()
    {
        parent::__construct();
        $this->load->driver('cache');
        $this->load->config('common/hot_api');
        $this->load->library('HttpUtil');
    }

    public function api($params)
    {
        $rid = $params['rid'] ? : 100001;
        $mcKey = "daily_hot_{$rid}";
        $result = $this->cache->memcached->get($mcKey);
        if ($result !== FALSE) {
            return $result;
        }

        $site = $this->config->item('daily');
        $site['data']['rule_id'] = $rid;
        $options['verify'] = false;
        $res = HttpUtil::cfg_request_options($site, $options);
        $res = json_decode($res, true);
        if (!empty($res)) {
            $this->cache->memcached->save($mcKey, $res, 300);
            return $res;
        } else {
            return [];
        }
    }
}
